<?php
use_stylesheet('data/main.css');
use_javascript('data/main.js');
use_javascript('publication/publicationrefresh.js');
?>
<script type="text/javascript">
    $(document).ready(function() {
        $(".edit").button({
             icons: {
                primary: "ui-icon-pencil"
            }
        });

        $("#lnkAddUser").button({
             icons: {
                primary: "ui-icon-plus"
            }
        });

        $("#lnkUploadData").button({
             icons: {
                primary: "ui-icon-plus"
            }
        });
    });
</script>

<table width="977px">
    <tr>
        <td colspan="2">
            <div class="datacontent">
                <?php if(!empty($research)): ?>
                    <?php include_component('approval', 'researchStatus', array('researchid' => $research->id)) ?>
                <?php endif;?>
            </div>
        </td>
    </tr>
    <tr>
        <td valign="top">
            <div class="datacontent">
                <h1 class="data">Document Information</h1>
                <?php include_partial('research', array('form' => $form, 'bibentry' => $bibentry)) ?>

            </div>
        </td>
        <td valign="top" width="348px">
            <div class="obs-area">
                <?php if(!empty($research)): ?>
                    <p class="highlight">Complete your observation data below.</p>
                    <div class="subheader">Observation
                        <a class="edit" title="Edit Observation" href="<?php echo url_for('data/showObservation?id='. $research->id) ?>">
                            <span>Edit</span></a>
                    </div>
                    <div class="subheader">Map Overlay
                        <a class="edit" title="Map Overlay" href="<?php echo url_for('data/showOverlay?id='. $research->id) ?>">
                            <span>Edit</span></a>
                    </div>
                    <div class="subheader">Collaborator
                        <a id="lnkAddUser" title="Add collaborator" onclick="return loadNewCollaborativeUserDialog(20,400,false,'dlgAddUser', <?php echo $research->id; ?>, 'txtRid');">
                            <span>Add User</span>
                        </a>
                    </div>
                    <?php $totalCollaborators = $research->getResearchgroup()->count(); $tempIndex = 0; ?>
                    <?php foreach ($research->getCollaboratorList(Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_REJECTED], true) as $researchGroup): ?>
                        <?php $tempIndex++; ?>
                            <span>
                            <?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?>

                            <?php if(($research->getEntityid() == $sf_user->getAttribute('currentuser')->getId()) || ($researchGroup->getCollaborativeentityid() == $sf_user->getAttribute('currentuser')->getId())): ?>
                                <a class="clickable" id="lnkRemoveCollaborativeUser" onclick="return removeCollaborativeUser(<?php echo $researchGroup->getCollaborativeentityid(); ?>, <?php echo $research->getId(); ?>);">
                                    (Remove)
                                </a>
                            <?php endif; ?>

                            <?php if($tempIndex < $totalCollaborators): ?>
                                <label>, </label>
                            <?php endif; ?>
                            </span>
                    <?php endforeach; ?>
                    <input id="txtRid" type="hidden"/>
                    <div id="boxes">
                        <div id="dlgAddUser" class="window ui-dialog ui-widget ui-widget-content ui-corner-all">
                            <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
                                <span class="ui-dialog-title" id="ui-dialog-title-observation-form-dialog">Invite collaborator</span>
                                <a onclick="javascript:$('.window').hide()" class="ui-dialog-titlebar-close ui-corner-all clickable" role="button">
                                    <span class="ui-icon ui-icon-closethick">close</span>
                                </a>
                            </div>
                            <table cellpadding="0" cellspacing="0" width="100%" style="padding: 10px; font-size: 90%">
                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                </tr>
                                <tr id="trErrorMessage">
                                    <td colspan="2">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td align="left">
                                        <span>User Name</span>
                                    </td>
                                    <td align="right">
                                        <input style="width: 290px; padding: 3px;" type="text" id="txtMailTo" onclick="javascript:LoadUserList();" class="ui-autocomplete-input required text ui-widget-content ui-corner-all"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td align="center">

                                    </td>
                                    <td align="right">
                                        <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="lnkAddUser" onclick="return addCollaborativeUser(document.getElementById('txtRid').value, $('#txtMailTo').val(), false);">
                                            <span class="ui-button-text">Add User</span>
                                        </button>
                                        <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="javascript:$('.window').hide();">
                                            <span class="ui-button-text">Cancel</span>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="subheader">Upload Data
                        <a id="lnkUploadData" class="edit" title="Edit Observation" href="<?php echo url_for('data/uploadData?id='.$research->id) ?>">
                            <span>Upload</span>
                        </a>
                    </div>
                <?php endif; ?>
            </div>
        </td>
    </tr>
</table>